package com.ysd.lis.controller;

import com.ysd.common.Result;
import com.ysd.common.dto.ColumnAndCommentDto;
import com.ysd.lis.annotation.LogDetail;
import com.ysd.lis.aspect.OperationType;
import com.ysd.lis.request.DynamicTablePageData;
import com.ysd.lis.request.TransmitTodoParam;
import com.ysd.lis.service.PublicTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @program: server_lis
 * @author: liuQi
 * @create: 2023-11-14 15:25
 */
@Api(tags = "公共任务表")
@RestController
@RequestMapping("/api/task/public")
public class PublicTaskController {
    @Autowired
    private PublicTaskService publicTaskService;

    @ApiOperation("模糊查询表名")
    @GetMapping("/findTableNames")
    public Result findTableNames() {
        return publicTaskService.findTableNames();
    }

    @ApiOperation("根据表名查询表字段")
    @GetMapping("/findColumnsByTableName/{tableName}")
    public Result findColumnsByTableName(@PathVariable("tableName") String tableName) {
        return publicTaskService.findColumnsByTableName(tableName);
    }

    @ApiOperation("根据表名查询表字段")
    @GetMapping("/getColumnsByTableName/{tableName}")
    public Result getColumnsByTableName(@PathVariable("tableName") String tableName) {
        return publicTaskService.getColumnsByTableName(tableName);
    }

    @ApiOperation("动态插入模版实例表数据")
    @PostMapping("/insertTransmitTodoData")
    @LogDetail(requestParam ="insertTransmitTodoData",operationType = OperationType.INSERT, module = "模版管理",content = "通过模版或者实例模块，增加【tableName】实例数据")
    public Result insertTransmitTodoData(@RequestBody TransmitTodoParam transmitTodoParam) {
        return publicTaskService.insertTransmitTodoData(transmitTodoParam);
    }

    @ApiOperation("动态编辑模版实例表数据")
    @PostMapping("/updateTransmitTodoTable")
    public Result updateTransmitTodoTable(@RequestBody TransmitTodoParam transmitTodoParam) {
        return publicTaskService.updateTransmitTodoTable(transmitTodoParam);
    }

    @ApiOperation("通过界面进行数据插入")
    @PostMapping("/pageInfoAddTransmitTodoTable")
    @LogDetail(requestParam ="insertTransmitTodoData",operationType = OperationType.INSERT, module = "模版管理",content = "通过模版或者实例模块，增加【title】模版实例数", businessName = "title")
    public Result pageInfoAddTransmitTodoTable(@RequestBody Map<String, Object> params) {
        return publicTaskService.pageInfoAddTransmitTodoTable(params);
    }

    @ApiOperation("通过表名动态查询数据")
    @GetMapping("/getDynamicTableData/{tableName}")
    public Result getDynamicTableData(@PathVariable("tableName") String tableName) {
        return publicTaskService.getDynamicTableData(tableName);
    }

    @ApiOperation("通过表名动态查询数据")
    @PostMapping("/getDynamicTablePageData")
    public Result getDynamicTablePageData(@RequestBody DynamicTablePageData dynamicTablePageData) {
        return publicTaskService.getDynamicTablePageData(dynamicTablePageData);
    }

    @ApiOperation("通过表名和ID删除数据")
    @GetMapping("/deleteDynamicTableData/{tableName}/{id}")
    public Result deleteDynamicTableData(@PathVariable("tableName") String tableName, @PathVariable("id") String id) {
        return publicTaskService.deleteDynamicTableData(id, tableName);
    }

    @ApiOperation("根据表名查询表字段返回驼峰结构")
    @GetMapping("/findColumnsCamelByTableName/{tableName}")
    public Result findColumnsCamelByTableName(@PathVariable("tableName") String tableName) {
        return publicTaskService.findColumnsByTableNameToCamel(tableName);
    }
}
